class Solution {
    public:
        int indexx[8] = {0,0,1,-1,-1,-1,1,1};
        int indexy[8] = {-1,1,0,0,-1,1,-1,1};
        int Surrounding_Number(vector<vector<char>>& board,int i,int j){
            int n = board.size(),m=board[0].size();
            int ret = 0;
            for(int k = 0 ; k < 8 ; k++){
                int row = i + indexx[k];
                int col = j + indexy[k];
                if(row >= 0 && row < n && col >=0 && col < m && board[row][col] == 'M'){
                    ret++;
                }
            }
            return ret;
        }
        bool is_bom(vector<vector<char>>& board,int i,int j){
            if(board[i][j] == 'M')  return false;
            return true;
        }
        vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {
            int  i = click[0],j=click[1];
            if(is_bom(board,i,j)){
                //不是炸弹
                dfs(board,i,j);
            }else{
                //是炸弹
                board[i][j] = 'X';
            }
            return board;
        }
        void dfs(vector<vector<char>>& board,int i,int j){
            int n = board.size(),m=board[0].size();
            int num = Surrounding_Number(board,i,j);
            if(num){
                board[i][j] = '0' + num;
                return;
                //周围有炸弹
            }else{
                //周围没炸弹
                board[i][j] = 'B';
            }
    
            for(int k = 0 ; k < 8 ; k++){
                int row = i + indexx[k];
                int col = j + indexy[k];
                if(row >= 0 && row < n && col >=0 && col <m && board[row][col] == 'E'){
                    dfs(board,row,col);
                }
            }
        }
    };
        